package buaa.paas.controller;

import buaa.paas.kubectl.PodUtil;
import buaa.paas.model.Response;
import io.kubernetes.client.openapi.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedList;
import java.util.List;
import java.util.TreeMap;
@CrossOrigin(origins = {"http://localhost:8080","null"})
@RestController
@RequestMapping("/pod")
public class PodController {
    @Autowired
    PodUtil podUtil;
    /**
     * 获取一个项目中全部pod的函数
     * @param uid 用户的id
     * @param aid 项目的id
     * */
    @PostMapping("/lsPods")
    public Response getPods(@RequestParam("uid") int uid, @RequestParam("aid") int aid){
        try{
            List<TreeMap<String, Object>> result = podUtil.getPodsFromNamespace(uid+"-"+aid);
            Response res = new Response(result);
            res.setCode(200);
            res.setMessage("查询成功");
            return res;
        }catch(ApiException e){
            return new Response(500, e.getMessage(), null);
        }
    }
}
